package com.woniuxy.d_cache;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.subject.Subject;

/**
 * @author lg
 * @time 2020/07/04 15:38:39
 */
public class App {
    public static void main(String[] args) {
        DefaultSecurityManager defaultSecurityManager=new DefaultSecurityManager ();
         MyRealm myRealm=new MyRealm ();
        defaultSecurityManager.setRealm (myRealm);

        EhCacheManager cacheManager=new EhCacheManager (); //创建缓存
        defaultSecurityManager.setCacheManager (cacheManager);

        SecurityUtils.setSecurityManager (defaultSecurityManager);

        Subject subject = SecurityUtils.getSubject ();
        UsernamePasswordToken token=new UsernamePasswordToken ("foo","123");

        try {
            subject.login (token);
            System.out.println ("ok");
        } catch (AuthenticationException e) {
            System.out.println ("not no");
        }

        System.out.println ("user:save" + subject.isPermitted ("user:save"));
        System.out.println("user:delete " + subject.isPermitted("user:delete"));
        System.out.println("user:update " + subject.isPermitted("user:update"));
        System.out.println("user:find " + subject.isPermitted("user:find"));
    }
}
